package vboot.core.module.ass.dict.cate;

import vboot.core.common.api.R;
import vboot.core.common.dao.Sqler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("ass/dict/cate")
public class AssDictCateApi {

    private String table = "ass_dict_cate";

    @GetMapping
    public R get(String name) {
        Sqler sqler = new Sqler(table);
        sqler.addLike("t.name", name);
        sqler.addSelect("t.notes,t.ornum");
        return R.ok(service.findPageData(sqler));
    }

    @GetMapping("one/{id}")
    public R getOne(@PathVariable String id) {
        AssDictCate cate = service.findOne(id);
        return R.ok(cate);
    }

    @PostMapping
    public R post(@RequestBody AssDictCate cate) {
        return R.ok(service.insert(cate));
    }

    @PutMapping
    public R put(@RequestBody AssDictCate cate) {
        return R.ok(service.update(cate));
    }

    @DeleteMapping("{ids}")
    public R delete(@PathVariable String[] ids) {
        return R.ok(service.delete(ids));
    }

    @Autowired
    private AssDictCateService service;

}
